﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SMS.Common.Silverlight
{
    public class DelegateCommand : ICommand
    {
        private Action<object> executeMethod;
        private Predicate<object> canExecuteMethod;

        public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
            : this(execute)
        {
            this.canExecuteMethod = canExecute;
        }

        public DelegateCommand(Action<object> execute)
        {
            this.executeMethod = execute;
        }

        public bool CanExecute(object parameter)
        {
            //if (CanExecuteChanged != null)
            //    CanExecuteChanged.Invoke(this, new EventArgs());
            if (canExecuteMethod != null)
                return canExecuteMethod(parameter);
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            if (CanExecute(parameter) && executeMethod != null)
                executeMethod(parameter);
        }
    }
}
